package com.easyaop.test.core.buddy;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

import java.lang.reflect.Method;
import java.util.Arrays;

public class LoggerAdvisor2 {
    @Advice.OnMethodEnter(skipOn = Advice.OnNonDefaultValue.class, skipOnIndex = 0)
    public static Object[] onMethodEnter(@Advice.Origin Method method
            , @Advice.AllArguments Object[] arguments
//            ,  @Advice.Return(readOnly = false) Object ret
    ) {
//        long l = System.currentTimeMillis();
        System.out.println("args " + Arrays.toString(arguments));
        //        return l;
//        ret="345";
        return new Object[]{"123", method, arguments};
    }

    //    @Advice.OnMethodEnter
    //            (skipOn = Advice.OnDefaultValue.class)
    public static Object onMethodEnter1(@Advice.Origin Method method, @Advice.AllArguments Object[] arguments) {
        long l = System.currentTimeMillis();
        System.out.println("args " + Arrays.toString(arguments));
        return 1;
    }


    @Advice.OnMethodExit
    public static void onMethodExit(@Advice.Origin Method method, @Advice.This Object thisObject, @Advice.AllArguments Object[] arguments
            , @Advice.Return(typing = Assigner.Typing.DYNAMIC,
                    readOnly = false)
                                    Object ret
                                    //            ,@Advice.Enter long startTime
    ) {
        System.out.println(""
//                "ret:" + ret
                        //                        + " , startTime: " +startTime
                        + " , this: " + thisObject + " , args: " + arguments
                //                +", throwable: "+throwable
        );

        ret = "112";
    }
}
